package com.hzw.monitor.mysqlbinlog.utils;

import java.util.ArrayList;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import com.hzw.monitor.mysqlbinlog.connection.ConnectionAttributes;
import com.hzw.monitor.mysqlbinlog.event.EventData;
import com.hzw.monitor.mysqlbinlog.event.EventHeader;
import com.hzw.monitor.mysqlbinlog.event.RowEventData;

public class DataUtils {
	private static final Logger logger = LogManager.getLogger(DataUtils.class);

	public static boolean handle(ConnectionAttributes myAttributes, EventHeader header, EventData eventData) {
		boolean result = true;
		RowEventData rowEventData = (RowEventData) eventData;
		if (myAttributes.accept(rowEventData.getDatabase(), rowEventData.getTable())) {
			// 接受才处理
			ArrayList<String> datas = eventData.toJson();
			if (null != datas) {
				for (String data : datas) {
					// result=MQUtils.sendMqQueue("kmonitor-binlog", data);
					// if(result==false)
					// {
					// 立刻返回
					// return false;
					// }
					LoggerUtils.debug(logger, data);
				}
			}
		}
		return result;
	}
}
